package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.BrandService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;


@Service
@DubboService
public class BrandServiceImpl implements BrandService {

    @Resource
    private TbBrandMapper brandMapper;
    //查询全部
    @Override
    public List<TbBrand> findAll(String name) {
        TbBrandExample brandExample = new TbBrandExample();
        if (name != null && !"".equals(name)){
            TbBrandExample.Criteria criteria = brandExample.createCriteria();
            criteria.andNameLike("%"+name+"%");
        }
        return brandMapper.selectByExample(brandExample);
    }

    //增加 brand 数据
    @Override
    public int addBrand(TbBrand brand) {
        return brandMapper.insert(brand);
    }

    //删除 brand 数据
    @Override
    public void deleteBrand(Long[] ids) {
        TbBrandExample tbBrandExample = new TbBrandExample();
        TbBrandExample.Criteria criteria = tbBrandExample.createCriteria();
        List<Long> list = Arrays.asList(ids);
        criteria.andIdIn(list);
        brandMapper.deleteByExample(tbBrandExample);
    }

    //回显方法
    @Override
    public TbBrand getById(Integer id) {
        return brandMapper.selectByPrimaryKey(Long.valueOf(id));
    }

    //修改数据
    @Override
    public int updateBrand(TbBrand brand) {
        return brandMapper.updateByPrimaryKey(brand);
    }
}
